﻿#region | Copyright © 2556 |

/*
##########################################################################
	Author By : Siriwat Suananpornpanit
	DateTime : 2556/08/30
##########################################################################
*/

#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Reflection;

namespace Web.Core
{
    public sealed class Assembly
    {
        private static Assembly _assembly;

        public static Assembly GetInstance()
        {
            _assembly = new Assembly();
            return _assembly;
        }

        internal void CallMethod(Type type, String method, Object[] message)
        {
            dynamic obj = Activator.CreateInstance(type);
            obj.method(message);
        }

        internal Object ReflectMethod(Type type, String method, Object[] message)
        {
            dynamic obj = Activator.CreateInstance(type);
            Object result = obj.method(message);
            return result;
        }

        internal Object ReflectMethod<T>(Type type, String method, Object[] message)
        {
            object obj = Activator.CreateInstance(type);
            return (T)type.InvokeMember(method,
                System.Reflection.BindingFlags.Instance |
                System.Reflection.BindingFlags.InvokeMethod |
                System.Reflection.BindingFlags.Public,
                null, 
                obj,
                message);
        }

        internal void OnReflectMethod(Page page, String methods, Object[] message)
        {
                page.GetType().InvokeMember(methods,
                System.Reflection.BindingFlags.InvokeMethod,
                null,
                page,
                message);
        }

        internal void OnReflectMasterPage(System.Web.UI.MasterPage master, String methods, Object[] message)
        {
            master.GetType().InvokeMember(methods,
            System.Reflection.BindingFlags.InvokeMethod,
            null,
            master,
            message);
        }
    }
}